package com.zhao.shiyuanbaoyou.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhao.shiyuanbaoyou.R;
import com.zhao.shiyuanbaoyou.bean.HomeBean;
import com.zhao.shiyuanbaoyou.bean.TenBean;
import com.zhao.shiyuanbaoyou.helper.RecyclerViewAdapterHelper;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by 张昭 on 2016/11/12.
 */

public class TenAdapter extends RecyclerViewAdapterHelper<TenBean.RowsBean> {
    private Context mContext;
    private List<TenBean.RowsBean> mList;

    public TenAdapter(Context context, List<TenBean.RowsBean> list) {
        super(context, list);
        this.mContext=context;
        this.mList=list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_fragment_home, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        DecimalFormat df=new DecimalFormat("0.0#");
        if (holder instanceof MyViewHolder) {

            Glide.with(mContext).load(mList.get(position).
                    getProductImg()).
                    into(((MyViewHolder) holder).imageView_fragment);
            ((MyViewHolder) holder).textView_Title.setText(mList.get(position).getName());
            ((MyViewHolder) holder).textView_money.setText(df.format(mList.get(position).getNewPrice()) + "");
            ((MyViewHolder) holder).textView_zhekou.setText(df.format(mList.get(position).getDiscount()));
            ((MyViewHolder) holder).textView_number.setText(mList.get(position).getSaleTotal() + "");
            ((MyViewHolder) holder).textView_oldmoney.setText(df.format(mList.get(position).getOldPrice())+"");
            if (mList.get(position).getIsBaoYou() == 1) {
                ((MyViewHolder) holder).textView_baoyou.setText("包邮");
            } else {
                ((MyViewHolder) holder).textView_baoyou.setText("不包邮");
            }
        }
    }
    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView_fragment;
        private TextView textView_Title,
                textView_money, textView_zhekou,
                textView_number, textView_baoyou, textView_oldmoney;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView_fragment = (ImageView) itemView.findViewById(R.id.imageView_item_fragment_home_image);
            textView_Title = (TextView) itemView.findViewById(R.id.textView_item_fragment_home_title);
            textView_money = (TextView) itemView.findViewById(R.id.textView_item_fragment_home_money);
            textView_zhekou = (TextView) itemView.findViewById(R.id.textView_item_fragment_home_context);
            textView_number = (TextView) itemView.findViewById(R.id.textView_item_fragment_home_number);
            textView_baoyou = (TextView) itemView.findViewById(R.id.textView_item_fragment_home_baoyou);
            textView_oldmoney = (TextView) itemView.findViewById(R.id.textView_item_fragment_home_oldmoney);

        }
    }
}
